<template>
  <div>
    <div class="app-container">
      <div class="search-container">
        <el-form :inline="true" :model="sheepfileQuery" class="demo-form-inline">
          <el-form-item label="可视耳号">
            <el-input v-model="sheepfileQuery.earTag" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="电子耳标号">
            <el-input v-model="sheepfileQuery.electEarNum" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="品种">
            <el-select v-model="sheepfileQuery.variety" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="杜泊" value="1" />
              <el-option label="澳洲白" value="2" />
              <el-option label="萨福克" value="3" />
              <el-option label="杜湖" value="4" />
              <el-option label="杜杜湖" value="5" />
              <el-option label="萨杜湖" value="6" />
              <el-option label="澳湖" value="7" />
              <el-option label="湖羊" value="8" />
              <el-option label="澳杜湖" value="9" />
            </el-select>
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="sheepfileQuery.sheepSex" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="公" :value="true" />
              <el-option label="母" :value="false" />
            </el-select>
          </el-form-item>
          <el-form-item label="出生日期">
            <el-date-picker v-model="sheepfileQuery.startDate" type="date" placeholder="开始日期" style="width: 150px;"
              clearable />-
            <el-date-picker v-model="sheepfileQuery.endDate" type="date" placeholder="结束日期" style="width: 150px;"
              clearable />
          </el-form-item>
          <el-form-item label="月龄">
            <el-input v-model="sheepfileQuery.startMonthold" placeholder="请输入" style="width: 150px;" clearable />
            -
            <el-input v-model="sheepfileQuery.endMonthold" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="生长阶段">
            <el-select v-model="sheepfileQuery.growthstage" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="乳羊" value="1" />
              <el-option label="保育" value="2" />
              <el-option label="后备公羊" value="3" />
              <el-option label="后背母羊" value="4" />
              <el-option label="后备羊" value="5" />
            </el-select>
          </el-form-item>
          <el-form-item label="位置">
            <el-input v-model="sheepfileQuery.buildingId" placeholder="请输入" style="width: 150px;" clearable />
            -
            <el-input v-model="sheepfileQuery.columnId" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="羊只类型">
            <el-select v-model="sheepfileQuery.sheepType" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="种公" value="1" />
              <el-option label="种母" value="2" />
              <el-option label="后裔" value="3" />
            </el-select>
          </el-form-item>
          <el-form-item label="基因等级">
            <el-select v-model="sheepfileQuery.geneticGrade" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="后背级" value="1" />
              <el-option label="核心级" value="2" />
              <el-option label="生产级" value="3" />
              <el-option label="未定级" value="4" />
            </el-select>
          </el-form-item>
          <el-form-item label="生产等级">
            <el-select v-model="sheepfileQuery.produceLevel" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="后背群" value="1" />
              <el-option label="生产级" value="2" />
              <el-option label="核心级" value="3" />
              <el-option label="未定级" value="4" />
            </el-select>
          </el-form-item>
          <el-form-item label="销售等级">
            <el-select v-model="sheepfileQuery.saleLevel" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="无" value="1" />
              <el-option label="未定级" value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="繁殖状态">
            <el-select v-model="sheepfileQuery.reproductionState" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="后备空怀" value="1" />
              <el-option label="返情空怀" value="2" />
              <el-option label="未孕空怀" value="3" />
              <el-option label="流产空怀" value="4" />
              <el-option label="空胎空怀" value="5" />
              <el-option label="断奶空怀" value="6" />
              <el-option label="妊娠" value="7" />
              <el-option label="哺乳" value="8" />
            </el-select>
          </el-form-item>
          <el-form-item label="繁殖状态天数">
            <el-input v-model="sheepfileQuery.startReproductionStateNum" placeholder="请输入" style="width: 150px;"
              clearable />
            -
            <el-input v-model="sheepfileQuery.endReproductionStateNum" placeholder="请输入" style="width: 150px;"
              clearable />
          </el-form-item>
          <el-form-item label="父耳号">
            <el-input v-model="sheepfileQuery.prantEarNum" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="母耳号">
            <el-input v-model="sheepfileQuery.matherEarNum" placeholder="请输入" style="width: 150px;" clearable />
          </el-form-item>
          <el-form-item label="在场状态">
            <el-select v-model="sheepfileQuery.presentState" placeholder="请选择" style="width: 150px;" clearable>
              <el-option label="在场" value="1" />
              <el-option label="待入场" value="2" />
              <el-option label="销售离场" value="3" />
              <el-option label="死亡离场" value="4" />
              <el-option label="淘汰已离场" value="5" />
              <el-option label="调拨离场" value="6" />
              <el-option label="死羔未入场" value="7" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="danger" @click="getSheepfile()">查询</el-button>
            <el-button>重置</el-button>
          </el-form-item>
        </el-form>
        <el-button type="danger" @click="toFSheepfile()"> ＋ 新增种公</el-button>
        <el-button type="danger" @click="toMSheepfile()"> ＋ 新增种母</el-button>
        <el-button type="danger" @click="toHSheepfile()"> ＋ 新增后裔</el-button>
        <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" />
          <el-table-column prop="sheepFileId" label="序号" />
          <el-table-column prop="earTag" label="可视耳号" />
          <el-table-column prop="variety" label="品种">
            <template v-slot="scope">
              <span v-if="scope.row.variety == 1">杜泊</span>
              <span v-else-if="scope.row.variety == 2">澳洲白</span>
              <span v-else-if="scope.row.variety == 3">萨福克</span>
              <span v-else-if="scope.row.variety == 4">杜湖</span>
              <span v-else-if="scope.row.variety == 5">杜杜湖</span>
              <span v-else-if="scope.row.variety == 6">萨杜湖</span>
              <span v-else-if="scope.row.variety == 7">澳湖</span>
              <span v-else-if="scope.row.variety == 8">湖羊</span>
              <span v-else-if="scope.row.variety == 9">澳杜湖</span>
            </template>
          </el-table-column>
          <el-table-column prop="sheepSex" label="性别">
            <template v-slot="scope">
              <el-tag v-if="scope.row.sheepSex == 1" type="primary">公</el-tag>
              <el-tag v-if="scope.row.sheepSex == 0" type="danger">母</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="electEarNum" label="电子耳标号" />
          <el-table-column prop="geneticGrade" label="基因等级">
            <template v-slot="scope">
              <span v-if="scope.row.geneticGrade == 1">后备级</span>
              <span v-else-if="scope.row.geneticGrade == 2">核心级</span>
              <span v-else-if="scope.row.geneticGrade == 3">生产级</span>
              <span v-else-if="scope.row.geneticGrade == 4">未定级</span>
            </template>
          </el-table-column>
          <el-table-column prop="prantEarNum" label="父亲耳号" />
          <el-table-column prop="matherEarNum" label="母亲耳号" />
          <el-table-column prop="birthDate" label="出生日期">
            <template v-slot="scope">
              {{ scope.row.birthDate.substring(0, 10) }}
            </template>
          </el-table-column>
          <el-table-column prop="admissionDate" label="入场日期">
            <template v-slot="scope">
              {{ scope.row.admissionDate.substring(0, 10) }}
            </template>
          </el-table-column>
          <el-table-column prop="birthPlace" label="出生场地" />
          <el-table-column prop="birthWeight" label="出生重(公斤)" />
          <el-table-column prop="ablactationWeight" label="断奶重" />
          <el-table-column prop="ablactationDate" label="断奶日期">
            <template v-slot="scope">

            </template>
          </el-table-column>
          <el-table-column prop="birthContent" label="备注" />
          <el-table-column prop="growthstage" label="生长阶段">
            <template v-slot="scope">
              <span v-if="scope.row.growthstage == 1">乳羊</span>
              <span v-else-if="scope.row.growthstage == 2">保育</span>
              <span v-else-if="scope.row.growthstage == 3">后备公羊</span>
              <span v-else-if="scope.row.growthstage == 4">后背母羊</span>
              <span v-else-if="scope.row.growthstage == 5">后背羊</span>
            </template>
          </el-table-column>
          <el-table-column prop="buildingName" label="栋舍" />
          <el-table-column prop="columnName" label="栏位" />
          <el-table-column prop="sheepType" label="羊只类型">
            <template v-slot="scope">
              <span v-if="scope.row.sheepType == 1">种公</span>
              <span v-else-if="scope.row.sheepType == 2">种母</span>
              <span v-else-if="scope.row.sheepType == 3">后裔</span>
            </template>
          </el-table-column>
          <el-table-column prop="produceLevel" label="生产等级">
            <template v-slot="scope">
              <span v-if="scope.row.produceLevel == 1">后备群</span>
              <span v-else-if="scope.row.produceLevel == 2">生产群</span>
              <span v-else-if="scope.row.produceLevel == 3">核心群</span>
              <span v-else-if="scope.row.produceLevel == 4">未定级</span>
            </template>
          </el-table-column>
          <el-table-column prop="saleLevel" label="销售等级">
            <template v-slot="scope">
              <span v-if="scope.row.saleLevel == 1">无</span>
              <span v-else-if="scope.row.saleLevel == 4">未定级</span>
            </template>
          </el-table-column>
          <el-table-column prop="reproductionState" label="繁殖状态">
            <template v-slot="scope">
              <span v-if="scope.row.reproductionState == 1">后备空怀</span>
              <span v-else-if="scope.row.reproductionState == 2">返情空怀</span>
              <span v-else-if="scope.row.reproductionState == 3">未孕空怀</span>
              <span v-else-if="scope.row.reproductionState == 4">流产空怀</span>
              <span v-else-if="scope.row.reproductionState == 5">空胎空怀</span>
              <span v-else-if="scope.row.reproductionState == 6">断奶空怀</span>
              <span v-else-if="scope.row.reproductionState == 7">妊娠</span>
              <span v-else-if="scope.row.reproductionState == 8">哺乳</span>
            </template>
          </el-table-column>
          <el-table-column prop="isPregnancy" label="是否妊检">
            <template v-slot="scope">
              <span v-if="scope.row.isPregnancy == 1">是</span>
              <span v-else-if="scope.row.isPregnancy == 0">否</span>
            </template>
          </el-table-column>
          <el-table-column prop="reproductionStateNum" label="繁殖状态天数" />
          <el-table-column prop="presentState" label="在场状态">
            <template v-slot="scope">
              <span v-if="scope.row.presentState == 1">在场</span>
              <span v-else-if="scope.row.presentState == 2">待入场</span>
              <span v-else-if="scope.row.presentState == 3">销售离场</span>
              <span v-else-if="scope.row.presentState == 4">死亡离场</span>
              <span v-else-if="scope.row.presentState == 5">淘汰已离场</span>
              <span v-else-if="scope.row.presentState == 5">调拨离场</span>
              <span v-else-if="scope.row.presentState == 5">死羔未入场</span>
            </template>
          </el-table-column>
          <el-table-column prop="createName" label="创建人" />
          <el-table-column prop="createTime" label="创建时间">
            <template v-slot="scope">
              {{ scope.row.createTime.substring(0, 10) }}
            </template>
          </el-table-column>
          <el-table-column prop="updateName" label="修改人" />
          <el-table-column prop="updateTime" label="修改时间">
            <template v-slot="scope">
              {{ scope.row.updateTime.substring(0, 10) }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="120px">
            <template #default="scope">
              <el-link type="primary" @click="toHSheepfilelist(scope.row.sheepFileId)">详情</el-link>&nbsp;
              <el-link type="primary" @click="getdelete(scope.row.sheepFileId)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>

        <el-pagination v-model:current-page="sheepfileQuery.pageIndex" v-model:page-size="sheepfileQuery.PageSize"
          :page-sizes="[10, 15, 20, 25]" :background="true" layout="total, sizes, prev, pager, next, jumper"
          :total="pageshow.totalCount" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">

import sheepfile from '@/api/ProductionManagement/index'
import { sheepfileQuery } from '@/api/ProductionManagement/model'
import { number } from 'echarts';
import { isNull } from 'lodash';
import { useRouter } from 'vue-router';

const router = useRouter()
//参数
const sheepfileQuery = reactive<sheepfileQuery>({
  earTag: "",
  electEarNum: "",
  variety: null,
  sheepSex: null,
  growthstage: null,
  buildingId: null,
  columnId: null,
  sheepType: null,
  geneticGrade: null,
  produceLevel: null,
  saleLevel: null,
  reproductionState: null,
  reproductionStateNum: 0,
  prantEarNum: "",
  matherEarNum: "",
  presentState: null,
  startDate: "",
  endDate: "",
  startMonthold: null,
  endMonthold: null,
  startReproductionStateNum: null,
  endReproductionStateNum: null,
  pageIndex: 1,
  PageSize: 10
})

const pageshow = reactive({
  totalCount: 0,
  pageCount: 0
})
const tableData: any = ref([])
const getSheepfile = () => {
  sheepfile.getList(sheepfileQuery).then((res: any) => {
    console.log('完整响应数据:', res);
    tableData.value = res.data.data,
      pageshow.totalCount = res.data.totalCount,
      pageshow.pageCount = res.data.pageCount
  })
}

//多选框
const multipleSelection = ref([])
const handleSelectionChange = (val: any) => {
  multipleSelection.value = val
}

//分页方法
const handleSizeChange = (val: number) => {
  sheepfileQuery.PageSize = val
  getSheepfile();
}
const handleCurrentChange = (val: number) => {
  sheepfileQuery.pageIndex = val
  getSheepfile();
}


//删除
const getdelete = (ids: number) => {
  const id = reactive({
    sheepFileId: ids
  })
  ElMessageBox.confirm(
    '确认要删除吗',
    '警告',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      sheepfile.deletesheepfile(id).then(res => {
        if (res.code > 0) {
          ElMessage.success('删除成功')
          getSheepfile()
        }
        else {
          ElMessage.error('删除失败')
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Delete canceled',
      })
    })
}


//新增种公跳转
const toFSheepfile = () => {
  router.push({
    name: "SheepFileFAdd",
  })
}
//新增种母跳转
const toMSheepfile = () => {
  router.push({
    name: "SheepFileMAdd",
  })
}
//新增后裔跳转
const toHSheepfile = () => {
  router.push({
    name: "SheepFileHAdd",
  })
}

//羊只详情跳转
const toHSheepfilelist = (sheepfileId: any) => {
  router.push({
    name: "SheepFileEdit",
    params: {
      sheepFileId: sheepfileId
    }
  })
}


onMounted(() => {
  getSheepfile()
})
</script>
